package com.un.ebs.workOrder.aspect;

import com.un.ebs.core.util.SecurityUtils;
import com.un.ebs.core.util.StringUtils;
import com.un.ebs.sys.service.ConfigureService;
import com.un.ebs.sys.service.WxService;
import com.un.ebs.workOrder.WorkOrderConfigureCode;
import com.un.ebs.workOrder.domain.WorkOrderExt;
import com.un.ebs.workOrder.service.WorkOrderService;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author liubo
 * @email liubocs@163.com
 * @date 2020/3/4 23:24
 */
@Aspect
@Component
public class WorkOrderNotifyAspect {

    @Resource
    private ConfigureService configureService;

    @Resource
    private WxService wxService;

    @Resource
    private WorkOrderService workOrderService;

    @AfterReturning(value = "execution(* com.un.ebs.workOrder.service.impl.WorkOrderServiceImpl.assign(com.un.ebs.workOrder.dto.WorkOrderAssignDto))", returning = "result")
    public void assignNotify(JoinPoint joinPoint, Object result) {
//        String templateId = configureService.getValueByCode(WorkOrderConfigureCode.work_order_assign_templete_id);
//        String config = configureService.getValueByCode(WorkOrderConfigureCode.work_order_assign_templete_config);
//        String url = StringUtils.valueReplace(configureService.getValueByCode(WorkOrderConfigureCode.work_order_assign_templete_url), "\\{", "\\}", SecurityUtils.getUserContent());
//
//        List<WorkOrderExt> list = workOrderService.queryByIds((List<String>) result);
//        for (WorkOrderExt wo : list) {
//            wxService.sendTemplateMessage(
//                    wo.getTenantId(),
//                    "新工单通知",
//                    wo.getAcceptUserId(),
//                    templateId,
//                    StringUtils.splitTemplate(config.split("~"), wo),
//                    url);
//        }
    }
}
